package com.company.thread;


import java.util.ArrayList;
import java.util.List;

/**
 * 保护性暂停线程模式测试
 */

public class GuardedTest2 {


    private static final GuardedObject2 lock = new GuardedObject2();
    public static void main(String[] args) {
        //线程1获取线程2下载的内容
        new Thread(()->{
            System.out.println("handler获取downloader下载的内容...");
            Object response = lock.getResponse(2000);
            System.out.println(response);
        },"handler").start();


        //线程2下载内容
        new Thread(()->{
            System.out.println("downloader下载内容...");
            List<String> li = Downloader.downloadBaiduPageToStrs();
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.finishResponse(li);
        },"downloader").start();





    }



}
